import 'package:hongsheng/api/SPClassApiManager.dart';
import 'package:hongsheng/api/SPClassHttpCallBack.dart';
import 'package:hongsheng/app/SPClassApplicaion.dart';
import 'package:hongsheng/model/SPClassBaseModelEntity.dart';
import 'package:hongsheng/model/MatchAiDetailEntity.dart';
import 'package:hongsheng/pages/common/SPClassDialogUtils.dart';
import 'package:hongsheng/pages/common/SPClassNoDataView.dart';
import 'package:hongsheng/pages/user/SPClassRechargeDiamondPage.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassDateUtils.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/SPClassStringUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/widgets/SPClassToolBar.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

///AI详情
class SPClassAiDetailPage extends StatefulWidget {
  final bool isFromMatch;
  final String ?matchId;
  final String matchType;
  const SPClassAiDetailPage({Key ?key,this.isFromMatch=false,this.matchId,this.matchType='足球'}) : super(key: key);

  @override
  _SPClassAiDetailPageState createState() => _SPClassAiDetailPageState();
}

class _SPClassAiDetailPageState extends State<SPClassAiDetailPage> {
  MatchAiDetailEntity ?data;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    return widget.isFromMatch?
    Container(
      child: Stack(
        children: <Widget>[
          Image.asset(
              SPClassImageUtil.spFunGetImagePath("ic_aidetail_bg"), //ic_basketball
              fit: BoxFit.fill, width: MediaQuery.of(context).size.width
          ),
          data==null?Center(child: SPClassNoDataView(),):
          SingleChildScrollView(
            child: Column(
              children: <Widget>[
                SizedBox(height: width(20),),
                analysisWidget(),
                SizedBox(height: width(20),),
                data?.spProInfo?.spProIsEmpty=='1'?emptyAiWidget():
                data?.spProAiVip?.spProIsAiVip=='0'&&data!.spProInfo!.spProAiList.isEmpty?unBuyWidget():SizedBox(),
                Column(
                  children: data!.spProInfo!.spProAiList.map((e){
                    return newGuessWidget(e);
                    return guessWidget(e);
                  }).toList(),
                ),

              ],
            ),
          ),
        ],
      ),
    ):
    Scaffold(
      appBar: SPClassToolBar(
        context,title: "AI预测详情",),
      body: Container(
        child: Stack(
          children: <Widget>[
            Image.asset(
                SPClassImageUtil.spFunGetImagePath("ic_aidetail_bg"), //ic_basketball
                fit: BoxFit.fill, width: MediaQuery.of(context).size.width
            ),
            data==null?Center(child: SPClassNoDataView(),):
            SingleChildScrollView(
              child: Column(
                children: <Widget>[
                  topItem(),
                  data?.spProInfo?.spProIsEmpty=='1'?emptyAiWidget():
                  data?.spProAiVip?.spProIsAiVip=='0'&&data!.spProInfo!.spProAiList.isEmpty?unBuyWidget():SizedBox(),
                  Column(
                    children: data!.spProInfo!.spProAiList.map((e){
                      return newGuessWidget(e);
                      return guessWidget(e);
                    }).toList(),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget lineWidget(){
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            RichText(
              text: TextSpan(
                  text: '${data?.spProInfo?.spProGuessMatch?.spProTeamOnePercent??0}',
                  style: TextStyle(fontSize: sp(15),color: Colors.white),
                  children: [
                    TextSpan(
                      text: '%',
                      style: TextStyle(fontSize: sp(12),color: Colors.white),
                    )
                  ]
              ),
            ),
            RichText(
              text: TextSpan(
                  text: '${data?.spProInfo?.spProGuessMatch?.spProTeamTwoPercent??0}',
                  style: TextStyle(fontSize: sp(15),color: Colors.white),
                  children: [
                    TextSpan(
                      text: '%',
                      style: TextStyle(fontSize: sp(12),color: Colors.white),
                    )
                  ]
              ),
            ),
          ],
        ),
        SizedBox(height: width(4),),
        Row(
          children: <Widget>[
            Expanded(
              flex:data?.spProInfo?.spProGuessMatch?.spProTeamOnePercent??0,
              child: Container(
                margin: EdgeInsets.only(right: 2),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Color(0xFFDE3C31),
                    borderRadius: BorderRadius.horizontal(left:Radius.circular(300) )
                ),
                height: width(10),
              ),
            ),
            Expanded(
              flex:data?.spProInfo?.spProGuessMatch?.spProTeamTwoPercent??0,
              child: Container(
                decoration: BoxDecoration(
                    color: Color(0xFF5D8AF7),
                    borderRadius: BorderRadius.horizontal(right:Radius.circular(300) )
                ),
                alignment: Alignment.center,
                height: width(10),
              ),
            ),
          ],
        ),
        SizedBox(height: width(4),),
        Text('AI对战双方能力分析',style: TextStyle(fontSize: sp(12),color: Colors.white),),
        (data!.spProInfo!.spProIsEmpty!='1'&&data?.spProAiVip?.spProIsAiVip=='0'&&data!.spProInfo!.spProAiList.isEmpty)?
        GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: (){
            if(spFunIsLogin(context: context)){
              spFunShowConfirmDialog(1);
            }
          },
          child: Container(
            width: width(120),
            height: width(40),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                // color: Color(0xFFE66000),
                // borderRadius: BorderRadius.circular(150),
              // border: Border.all(color: Color(0xFF38DEFF),width: 0.4),
              image: DecorationImage(
                fit: BoxFit.fitWidth,
                image: AssetImage(SPClassImageUtil.spFunGetImagePath('ic_single_buy'),),
              )
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(data?.spProAiVip?.spProAiSinglePrice??'',style: TextStyle(color: Colors.white,fontSize: sp(14),fontWeight: FontWeight.bold),),
                Image.asset(
                    SPClassImageUtil.spFunGetImagePath("zhuanshi"),
                    fit: BoxFit.fill, width:width(22)
                ),
                Text('解锁',style: TextStyle(color: Colors.white,fontSize: sp(12)),),
              ],
            ),
          ),
        ):SizedBox(),
      ],
    );
  }

  Widget topItem(){
    return Container(
      margin: EdgeInsets.symmetric(horizontal: width(15),vertical: width(23)),
      padding: EdgeInsets.symmetric(horizontal: width(15)),
      width: MediaQuery.of(context).size.width,
      height: width(255),
      decoration: BoxDecoration(
        image: DecorationImage(
            fit: BoxFit.fitWidth,
            image: AssetImage(
              SPClassImageUtil.spFunGetImagePath("ic_aidetail_top"),
            )
        )
      ),
      child: Column(
        children: <Widget>[
          SizedBox(height: width(1),),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Image.asset(
                  SPClassImageUtil.spFunGetImagePath(widget.matchType=='足球'?"ic_football":'ic_basketball'),
                  color: Colors.white,
                  fit: BoxFit.fill, width:width(12)
              ),
              Text('   ${SPClassDateUtils.spFunDateFormatByString(data?.spProInfo?.spProGuessMatch?.spProStTime??'', "MM-dd HH:mm")} ${data?.spProInfo?.spProGuessMatch?.spProLeagueName??''}',style: TextStyle(fontSize: sp(12),color: Colors.white),)
            ],
          ),
          SizedBox(height: width(30),),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Column(
                children: <Widget>[
                  SPClassImageUtil.spFunNetWordImage(
                      placeholder: "ic_team_one",
                      url:data?.spProInfo?.spProGuessMatch?.spProIconUrlOne??'',
                      width: width(46),
                      height:  width(46)),
                  Text(SPClassStringUtils.spFunMaxLength(data?.spProInfo?.spProGuessMatch?.spProTeamOne??'',length: 5),style: TextStyle(fontSize: sp(13),color: Colors.white),)
                ],
              ),
              Container(
                margin: EdgeInsets.only(left: width(46),right: width(46),),
                child:Text('${data!.spProInfo!.spProGuessMatch!.spProScoreOne}-${data!.spProInfo!.spProGuessMatch!.spProScoreTwo}',style: TextStyle(fontSize: sp(22),fontWeight: FontWeight.w600,color: Colors.white),),
              ),
              Column(
                children: <Widget>[
                  SPClassImageUtil.spFunNetWordImage(
                      placeholder: "ic_team_two",
                      url:data?.spProInfo?.spProGuessMatch?.spProIconUrlTwo??'',
                      width: width(46),
                      height:  width(46)),
                  Text(SPClassStringUtils.spFunMaxLength(data?.spProInfo?.spProGuessMatch?.spProTeamTwo??'',length: 5),style: TextStyle(fontSize: sp(13),color: Colors.white),)
                ],
              ),
            ],
          ),
          SizedBox(height: width(20),),
          data?.spProInfo?.spProIsEmpty!='1'&&data?.spProAiVip?.spProIsAiVip=='0'&&data!.spProInfo!.spProAiList.isEmpty?SizedBox():Container(
            height: 1,
            color: Color(0xFF38DEFF).withOpacity(0.6),
          ),
          data?.spProInfo?.spProIsEmpty!='1'&& data?.spProAiVip?.spProIsAiVip=='0'&&data!.spProInfo!.spProAiList.isEmpty?SizedBox():SizedBox(height: width(20),),
          lineWidget(),

        ],
      ),
    );
  }

// 能力分析
  Widget  analysisWidget(){
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.symmetric(horizontal: width(15)),
          child: Row(
            children: <Widget>[
              Container(
                width: width(2),
                height: width(14),
                decoration: BoxDecoration(
                    color: Color(0xFFDE3C31),
                    borderRadius: BorderRadius.circular(100)
                ),
              ),
              SizedBox(width: 4,),
              Text("能力分析",style: TextStyle(fontSize: sp(13),color: Colors.white),),
            ],
          ),
        ),
        SizedBox(height: width(12),),
        Container(
          margin: EdgeInsets.symmetric(horizontal: width(15)),
          padding: EdgeInsets.symmetric(horizontal: width(15)),
          width: MediaQuery.of(context).size.width,
          height: data!.spProAiVip!.spProIsAiVip=='0'?width(129):width(77),
          alignment: Alignment.center,
          decoration: BoxDecoration(
              image: DecorationImage(
                  fit: BoxFit.fitWidth,
                  image: AssetImage(
                    SPClassImageUtil.spFunGetImagePath(data!.spProAiVip!.spProIsAiVip=='0'?"ic_aidetail_main2":"ic_aidetail_main"),
                  )
              )
          ),
          child: lineWidget(),
        ),

      ],
    );
  }

  //  竞彩
  Widget guessWidget(MatchAiDetailInfoAiEntity e){
    return Stack(
      children: <Widget>[
        Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.symmetric(horizontal: width(15)),
              child: Row(
                children: <Widget>[
                  Container(
                    width: width(2),
                    height: width(14),
                    decoration: BoxDecoration(
                        color: Color(0xFFDE3C31),
                        borderRadius: BorderRadius.circular(100)
                    ),
                  ),
                  SizedBox(width: 4,),
                  Text("${e.spProPlayingWay}预测率",style: TextStyle(fontSize: sp(13),color: Colors.white),),
                ],
              ),
            ),
            SizedBox(height: width(12),),
            Container(
              margin: EdgeInsets.symmetric(horizontal: width(15)),
              padding: EdgeInsets.symmetric(horizontal: width(15)),
              width: MediaQuery.of(context).size.width,
              height: width(77),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      fit: BoxFit.fitWidth,
                      image: AssetImage(
                        SPClassImageUtil.spFunGetImagePath("ic_aidetail_main"),
                      )
                  )
              ),
              child: Column(
                children: <Widget>[
                  SizedBox(height: width(6),),
                  Text('本场推荐${getGuessType(e.spProSupportWhich=='0'?1:e.spProSupportWhich=='1'?0:2, e.spProPlayingWay!)}${getValue(e.spProSupportWhich=='0'?1:e.spProSupportWhich=='1'?0:2,e)}',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
                  SizedBox(height: width(6),),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      e.spProPlayingWay=='让球胜平负'?Text(double.parse(e.spProAddScore!) ==0
                          ? "0": double.parse(e.spProAddScore!) >0
                          ? ("+"+SPClassStringUtils.spFunSqlitZero(e.spProAddScore!)): SPClassStringUtils.spFunSqlitZero(e.spProAddScore!),style: TextStyle(color: Colors.white,fontSize: sp(14))):Container(),
                      SizedBox(width: width(8),),
                      Expanded(
                        child: Stack(
                          children: <Widget>[
                            Container(
                              width: width(90),
                              height: width(27),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: e.spProSupportWhich=='1'?Color(0xFF38DEFF).withOpacity(0.6):MyColors.grey_99.withOpacity(0.3),
                              ),
                              child: Text('${getGuessType(0, e.spProPlayingWay!)}${getValue(0,e)}',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
                            ),
                            Visibility(
                              child: Positioned(
                                top: width(5),
                                left: width(5),
                                child: Image.asset(
                                  SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                  width: width(18),
                                ),
                              ),
                              visible: e.spProSupportWhich=='1',
                            ),
                            // Visibility(
                            //   visible: e.spProWhichWin=='1',
                            //   child: Positioned(
                            //     top: width(5),
                            //     right: width(5),
                            //     child: Image.asset(
                            //       SPClassImageUtil.spFunGetImagePath('ic_win',),
                            //       width: width(16),
                            //     ),
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                      SizedBox(width: width(8),),
                      Expanded(
                        child: Stack(
                          children: <Widget>[
                            Container(
                              width: width(90),
                              height: width(27),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color:!(e.spProPlayingWay!.contains('平'))?Colors.transparent:e.spProSupportWhich=='0'?Color(0xFF38DEFF).withOpacity(0.6):MyColors.grey_99.withOpacity(0.3),
                              ),
                              child: Text('${getGuessType(1, e.spProPlayingWay!)}${getValue(1,e)}',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
                            ),
                            Visibility(
                              child: Positioned(
                                top: width(5),
                                left: width(5),
                                child: Image.asset(
                                  SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                  width: width(18),
                                ),
                              ),
                              visible: e.spProSupportWhich=='0',
                            ),
                            // Visibility(
                            //   visible: e.spProWhichWin=='0',
                            //   child: Positioned(
                            //     top: width(5),
                            //     right: width(5),
                            //     child: Image.asset(
                            //       SPClassImageUtil.spFunGetImagePath('ic_win',),
                            //       width: width(16),
                            //     ),
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                      SizedBox(width: width(8),),
                      Expanded(
                        child: Stack(
                          children: <Widget>[
                            Container(
                              width: width(90),
                              height: width(27),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: e.spProSupportWhich=='2'?Color(0xFF38DEFF).withOpacity(0.6):MyColors.grey_99.withOpacity(0.3),
                              ),
                              child: Text('${getGuessType(2, e.spProPlayingWay!)}${getValue(2,e)}',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
                            ),
                            Visibility(
                              child: Positioned(
                                top: width(5),
                                left: width(5),
                                child: Image.asset(
                                  SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                  width: width(18),
                                ),
                              ),
                              visible: e.spProSupportWhich=='2',
                            ),
                            // Visibility(
                            //   visible: e.spProWhichWin=='2',
                            //   child: Positioned(
                            //     top: width(5),
                            //     right: width(5),
                            //     child: Image.asset(
                            //       SPClassImageUtil.spFunGetImagePath('ic_win',),
                            //       width: width(16),
                            //     ),
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                    ],
                  )
                ],
              ),
            ),
            SizedBox(height: width(20),),

          ],
        ),
        Positioned(
          top: 10,
          right:  width(13) ,
          child: Image.asset(
            (e.spProIsWin=="1")? SPClassImageUtil.spFunGetImagePath("ic_result_red"):
            (e.spProIsWin=="0")? SPClassImageUtil.spFunGetImagePath("ic_result_hei"):
            (e.spProIsWin=="2")? SPClassImageUtil.spFunGetImagePath("ic_result_zou"):"",
            width: width(40),
          ),
        ),
      ],
    );
  }

  Widget newGuessWidget(MatchAiDetailInfoAiEntity e){
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.symmetric(horizontal: width(15)),
          child: Row(
            children: <Widget>[
              Container(
                width: width(2),
                height: width(14),
                decoration: BoxDecoration(
                    color: Color(0xFF05F6CB),
                    borderRadius: BorderRadius.circular(100)
                ),
              ),
              SizedBox(width: 4,),
              Text("${e.spProPlayingWay}预测率",style: TextStyle(fontSize: sp(13),color: Colors.white),),
              // Text("(60篇)",style: TextStyle(fontSize: sp(10),color: Colors.white.withOpacity(0.7)),),
            ],
          ),
        ),
        SizedBox(height: width(12),),
        Container(
            margin: EdgeInsets.symmetric(horizontal: width(15)),
            padding: EdgeInsets.symmetric(horizontal: width(15)),
            width: MediaQuery.of(context).size.width,
            height:e.spProBigShot!=null?width(193): width(96),
            alignment: Alignment.center,
            decoration: BoxDecoration(
                image: DecorationImage(
                    fit: BoxFit.fitWidth,
                    image: AssetImage(
                      SPClassImageUtil.spFunGetImagePath(e.spProBigShot!=null?"ic_ai_double_bg":"ic_ai_single_bg"),
                    )
                )
            ),
            child: Column(
              children: [
                SizedBox(height: width(16),),
                Row(
                  children: [
                    Text('全部统计',style: TextStyle(fontSize: sp(13),color: Colors.white),)
                  ],
                ),
                SizedBox(height: width(10),),
                Row(
                  children: <Widget>[
                    Expanded(
                      flex: 1,
                      child: Container(
                        alignment: Alignment.centerLeft,
                        child: Row(
                          children: [
                            Visibility(
                              child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                width: width(18),
                              ),
                              visible: e.spProSupportWhich=='1',
                            ),
                            RichText(
                              text: TextSpan(
                                  text: getGuessType(0, e.spProPlayingWay!),
                                  style: TextStyle(fontSize: sp(12),color: Colors.white),
                                  children: [
                                    TextSpan(
                                      text: '${e.spProLeftNum}%',
                                      style: TextStyle(fontSize: sp(12),color: Color(0xFFDE3C31)),
                                    )
                                  ]
                              ),
                            ),
                            Visibility(
                              visible: e.spProWhichWin=='1',
                              child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_win',),
                                width: width(20),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Container(
                        alignment: Alignment.center,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Visibility(
                              child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                width: width(18),
                              ),
                              visible: e.spProSupportWhich=='0',
                            ),
                            RichText(
                              text: TextSpan(
                                  text: getGuessType(1, e.spProPlayingWay!),
                                  style: TextStyle(fontSize: sp(12),color: Colors.white),
                                  children: [
                                    TextSpan(
                                      text: e.spProPlayingWay!.contains('平')?'平${e.spProContentNum}%':'${getValue(1,e)}',
                                      style: TextStyle(fontSize: sp(12),color:e.spProPlayingWay!.contains('平')? Color(0xFF31DE42):Colors.white),
                                    )
                                  ]
                              ),
                            ),
                            Visibility(
                              visible: e.spProWhichWin=='0'&&e.spProPlayingWay!.contains('平'),
                              child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_win',),
                                width: width(20),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Container(
                        alignment: Alignment.centerRight,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: [
                            Visibility(
                              child:Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                width: width(18),
                              ),
                              visible: e.spProSupportWhich=='2',
                            ),
                            RichText(
                              text: TextSpan(
                                  text: getGuessType(2, e.spProPlayingWay!),
                                  style: TextStyle(fontSize: sp(12),color: Colors.white),
                                  children: [
                                    TextSpan(
                                      text: '${e.spProRightNum}%',
                                      style: TextStyle(fontSize: sp(12),color: Color(0xFF389CFF)),
                                    )
                                  ]
                              ),
                            ),
                            Visibility(
                              visible: e.spProWhichWin=='2',
                              child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath('ic_win',),
                                width: width(20),
                              ),
                            ),

                          ],
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(height: width(4),),
                Row(
                  children: <Widget>[
                    Expanded(
                      flex:int.parse(e.spProLeftNum!),
                      child: Container(
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Color(0xFFDE3C31),
                          // borderRadius: BorderRadius.horizontal(left:Radius.circular(300) )
                        ),
                        height: width(4),
                      ),
                    ),
                    Expanded(
                      flex:int.parse(e.spProContentNum!),
                      child: Container(
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Color(0xFF31DE42),
                        ),
                        height: width(4),
                      ),
                    ),
                    Expanded(
                      flex:int.parse(e.spProRightNum!),
                      child: Container(
                        decoration: BoxDecoration(
                          color: Color(0xFF389CFF),
                          // borderRadius: BorderRadius.horizontal(right:Radius.circular(300) )
                        ),
                        alignment: Alignment.center,
                        height: width(4),
                      ),
                    ),
                  ],
                ),

                e.spProBigShot==null?SizedBox():
                Column(
                  children: [
                    SizedBox(height: width(38),),
                    Row(
                      children: [
                        Text('大咖推荐',style: TextStyle(fontSize: sp(13),color: Colors.white),)
                      ],
                    ),
                    SizedBox(height: width(10),),
                    Row(
                      children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Row(
                              children: [
                                Visibility(
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                    width: width(18),
                                  ),
                                  visible: e.spProBigShot!.spProSupportWhich=='1',
                                ),
                                RichText(
                                  text: TextSpan(
                                      text: getGuessType(0, e.spProBigShot!.spProPlayingWay!),
                                      style: TextStyle(fontSize: sp(12),color: Colors.white),
                                      children: [
                                        TextSpan(
                                          text: '${e.spProBigShot!.spProLeftNum}%',
                                          style: TextStyle(fontSize: sp(12),color: Color(0xFFDE3C31)),
                                        )
                                      ]
                                  ),
                                ),
                                Visibility(
                                  visible: e.spProBigShot!.spProWhichWin=='1',
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_win',),
                                    width: width(20),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.center,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Visibility(
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                    width: width(18),
                                  ),
                                  visible: e.spProBigShot!.spProSupportWhich=='0',
                                ),
                                RichText(
                                  text: TextSpan(
                                      text: getGuessType(1, e.spProBigShot!.spProPlayingWay!),
                                      style: TextStyle(fontSize: sp(12),color: Colors.white),
                                      children: [
                                        TextSpan(
                                          text: e.spProBigShot!.spProPlayingWay!.contains('平')?'${e.spProBigShot!.spProContentNum}%':'${getValue(1,e)}',
                                          style: TextStyle(fontSize: sp(12),color:e.spProBigShot!.spProPlayingWay!.contains('平')? Color(0xFF31DE42):Colors.white),
                                        )
                                      ]
                                  ),
                                ),
                                Visibility(
                                  visible: e.spProBigShot?.spProWhichWin=='0',
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_win',),
                                    width: width(20),
                                  ),
                                ),

                              ],
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.centerRight,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Visibility(
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_tui',),
                                    width: width(18),
                                  ),
                                  visible: e.spProBigShot!.spProSupportWhich=='2',
                                ),
                                RichText(
                                  text: TextSpan(
                                      text: getGuessType(2, e.spProBigShot!.spProPlayingWay!),
                                      style: TextStyle(fontSize: sp(12),color: Colors.white),
                                      children: [
                                        TextSpan(
                                          text: '${e.spProBigShot?.spProRightNum}%',
                                          style: TextStyle(fontSize: sp(12),color: Color(0xFF389CFF)),
                                        )
                                      ]
                                  ),
                                ),
                                Visibility(
                                  visible: e.spProBigShot?.spProWhichWin=='2',
                                  child: Image.asset(
                                    SPClassImageUtil.spFunGetImagePath('ic_win',),
                                    width: width(20),
                                  ),
                                ),

                              ],
                            ),
                          ),
                        ),


                      ],
                    ),
                    SizedBox(height: width(4),),
                    Row(
                      children: <Widget>[
                        Expanded(
                          flex:int.parse(e.spProBigShot!.spProLeftNum!),
                          child: Container(
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Color(0xFFDE3C31),
                              // borderRadius: BorderRadius.horizontal(left:Radius.circular(300) )
                            ),
                            height: width(4),
                          ),
                        ),
                        Expanded(
                          flex:int.parse(e.spProBigShot!.spProContentNum!),
                          child: Container(
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: Color(0xFF31DE42),
                            ),
                            height: width(4),
                          ),
                        ),
                        Expanded(
                          flex:int.parse(e.spProBigShot!.spProRightNum!),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xFF389CFF),
                              // borderRadius: BorderRadius.horizontal(right:Radius.circular(300) )
                            ),
                            alignment: Alignment.center,
                            height: width(4),
                          ),
                        ),
                      ],
                    ),
                  ],
                )

              ],
            )
        ),
        SizedBox(height: width(20),),
      ],
    );
  }

  String getGuessType(int i,String playWay,){
    String guessType ='';
    if(playWay.contains('让球胜负')){
      if(i==0){
        guessType ='主胜';
      }
      if(i==1){
        guessType ='';
      }
      if(i==2){
        guessType ='客胜';
      }
    }
    if(playWay.contains('大小')){
      if(i==0){
        guessType ='大';
      }
      if(i==1){
        guessType ='';
      }
      if(i==2){
        guessType ='小';
      }
    }
    if(playWay.contains('让分胜负')||playWay.contains('让局胜负')){
      if(i==0){
        guessType ='主胜';
      }
      if(i==1){
        guessType ='';
      }
      if(i==2){
        guessType ='客胜';
      }
    }
    if(playWay.contains('总时长')||playWay.contains('总击杀')){
      if(i==0){
        guessType ='大于';
      }
      if(i==1){
        guessType ='';
      }
      if(i==2){
        guessType ='小于';
      }
    }
    if(playWay.contains('平')){
      if(i==0){
        guessType ='主胜';
      }
      if(i==1){
        guessType ='平';
      }
      if(i==2){
        guessType ='客胜';
      }
    }
    return guessType;
  }

  getValue(int i,MatchAiDetailInfoAiEntity e,){
    var value ='';
    if(e.spProPlayingWay!.contains('让球胜负')){
      if(i==0){
        value =e.spProWinOddsOne!;
      }
      if(i==1){
        value =e.spProAddScore!;
      }
      if(i==2){
        value =e.spProWinOddsTwo!;
      }
    }
    if(e.spProPlayingWay!.contains('大小')){
      if(i==0){
        value =double.tryParse(e.spProWinOddsOne!)!.toStringAsFixed(2);
      }
      if(i==1){
        value =SPClassStringUtils.spFunSqlitZero(SPClassStringUtils.spFunPanKouData(e.spProMidScore!).replaceAll("+", ""))+(widget.matchType=="足球"? "球":"");
      }
      if(i==2){
        value =double.tryParse(e.spProWinOddsTwo!)!.toStringAsFixed(2);
      }
    }
    if(e.spProPlayingWay!.contains('让分胜负')||e.spProPlayingWay!.contains('让局胜负')){
      if(i==0){
        value =double.tryParse(e.spProWinOddsOne!)!.toStringAsFixed(2);
      }
      if(i==1){
        value =SPClassStringUtils.spFunSqlitZero(SPClassStringUtils.spFunPanKouData(e.spProAddScore!,));
      }
      if(i==2){
        value =double.tryParse(e.spProWinOddsTwo!)!.toStringAsFixed(2);
      }
    }
    if(e.spProPlayingWay!.contains('总时长')||e.spProPlayingWay!.contains('总击杀')){
      if(i==0){
        value =double.tryParse(e.spProWinOddsOne!)!.toStringAsFixed(2);
      }
      if(i==1){
        value =(SPClassStringUtils.spFunSqlitZero(e.spProMidScore!)+(e.spProPlayingWay=="总时长"? "分钟":""));
      }
      if(i==2){
        value =double.tryParse(e.spProWinOddsTwo!)!.toStringAsFixed(2);
      }
    }
    if(e.spProPlayingWay!.contains('平')){
      if(i==0){
        value =double.tryParse(e.spProWinOddsOne!)!.toStringAsFixed(2);
      }
      if(i==1){
        value =e.spProDrawOdds!;
      }
      if(i==2){
        value =double.tryParse(e.spProWinOddsTwo!)!.toStringAsFixed(2);
      }
    }

    return value;
  }


  Widget unBuyWidget(){
    return Container(
      margin: EdgeInsets.only(left: width(15),right: width(15)),
      child: Column(
        children: [
          Stack(
            children: <Widget>[
              Image.asset(
                  SPClassImageUtil.spFunGetImagePath("ic_unbuy_bg"), //ic_basketball
                  fit: BoxFit.fill, width: MediaQuery.of(context).size.width
              ),
              Positioned(
                left: 0,
                right: 0,
                top: width(15),
                child:  Column(
                  children: <Widget>[
                    RichText(
                      text: TextSpan(
                          children: [
                            TextSpan(
                                text: '周订阅套餐：',
                                style: TextStyle(fontSize: sp(17),color: Colors.white,)
                            ),
                            TextSpan(
                                text: '${data?.spProAiVip?.spProAiWeekPrice??0}',
                                style: TextStyle(fontSize: sp(19),color: Colors.red,)
                            ),
                            TextSpan(
                                text: '钻石',
                                style: TextStyle(fontSize: sp(17),color: Colors.white,)
                            ),
                          ]
                      ),
                    ),
                    Text('${SPClassDateUtils.spFunDateFormatByString(DateTime.now().toString(), "MM月dd日")}-${SPClassDateUtils.spFunDateFormatByString(DateTime.now().add(Duration(days: 7)).toString(), "MM月dd日")}所有预测',style: TextStyle(fontSize: sp(12),color: Colors.white.withOpacity(0.8)),),
                    SizedBox(height: width(12),),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        GestureDetector(
                          onTap: (){
                            if(spFunIsLogin(context: context)){
                              spFunShowConfirmDialog(2);
                            }
                          },
                          child: Container(
                            // width: width(70),
                            // height: width(30),
                            width: width(120),
                            height: width(40),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              // color: MyColors.main1,
                              // borderRadius: BorderRadius.circular(150),
                                image: DecorationImage(
                                  fit: BoxFit.fitWidth,
                                  image: AssetImage(SPClassImageUtil.spFunGetImagePath('ic_week_buy'),),
                                )
                            ),
                            child: Text('立即订阅',style: TextStyle(color: Colors.white,fontSize: sp(12)),),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              )
            ],
          ),
          SizedBox(height: width(10)),
          Stack(
            children: <Widget>[
              Image.asset(
                  SPClassImageUtil.spFunGetImagePath("ic_unbuy_bg"), //ic_basketball
                  fit: BoxFit.fill, width: MediaQuery.of(context).size.width
              ),
              Positioned(
                left: 0,
                right: 0,
                top: width(15),
                child:  Column(
                  children: <Widget>[
                    RichText(
                      text: TextSpan(
                          children: [
                            TextSpan(
                                text: '月订阅套餐：',
                                style: TextStyle(fontSize: sp(17),color: Colors.white,)
                            ),
                            TextSpan(
                                text: '${data?.spProAiVip?.spProAiPrice??0}',
                                style: TextStyle(fontSize: sp(19),color: Colors.red,)
                            ),
                            TextSpan(
                                text: '钻石',
                                style: TextStyle(fontSize: sp(17),color: Colors.white,)
                            ),
                          ]
                      ),
                    ),
                    Text('${SPClassDateUtils.spFunDateFormatByString(DateTime.now().toString(), "MM月dd日")}-${SPClassDateUtils.spFunDateFormatByString(DateTime.now().add(Duration(days: 30)).toString(), "MM月dd日")}所有预测',style: TextStyle(fontSize: sp(12),color: Colors.white.withOpacity(0.8)),),
                    SizedBox(height: width(12),),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        // GestureDetector(
                        //   behavior: HitTestBehavior.translucent,
                        //   onTap: (){
                        //     if(spFunIsLogin(context: context)){
                        //       spFunShowConfirmDialog(isSingle: true);
                        //     }
                        //   },
                        //   child: Container(
                        //     width: width(120),
                        //     height: width(40),
                        //     alignment: Alignment.center,
                        //     decoration: BoxDecoration(
                        //         // color: Color(0xFFE66000),
                        //         // borderRadius: BorderRadius.circular(150),
                        //       // border: Border.all(color: Color(0xFF38DEFF),width: 0.4),
                        //       image: DecorationImage(
                        //         fit: BoxFit.fitWidth,
                        //         image: AssetImage(SPClassImageUtil.spFunGetImagePath('ic_single_buy'),),
                        //       )
                        //     ),
                        //     child: Row(
                        //       mainAxisAlignment: MainAxisAlignment.center,
                        //       children: <Widget>[
                        //         Text('${data.spProAiVip.spProAiSinglePrice??''}',style: TextStyle(color: Colors.white,fontSize: sp(14),fontWeight: FontWeight.bold),),
                        //         Image.asset(
                        //             SPClassImageUtil.spFunGetImagePath("zhuanshi"),
                        //             fit: BoxFit.fill, width:width(22)
                        //         ),
                        //         Text(' 解锁',style: TextStyle(color: Colors.white,fontSize: sp(12)),),
                        //       ],
                        //     ),
                        //   ),
                        // ),
                        GestureDetector(
                          onTap: (){
                            if(spFunIsLogin(context: context)){
                              spFunShowConfirmDialog(3);
                            }
                          },
                          child: Container(
                            // width: width(70),
                            // height: width(30),
                            width: width(120),
                            height: width(40),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              // color: MyColors.main1,
                              // borderRadius: BorderRadius.circular(150),
                                image: DecorationImage(
                                  fit: BoxFit.fitWidth,
                                  image: AssetImage(SPClassImageUtil.spFunGetImagePath('ic_ai_buy'),),
                                )
                            ),
                            child: Text('立即订阅',style: TextStyle(color: Colors.white,fontSize: sp(12)),),
                          ),
                        ),
                      ],
                    ),

                  ],
                ),
              )
            ],
          ),
        ],
      ),
    );
  }

  Widget emptyAiWidget(){
    return Container(
      margin: EdgeInsets.symmetric(horizontal: width(15)),
      padding: EdgeInsets.symmetric(horizontal: width(15)),
      width: MediaQuery.of(context).size.width,
      height: width(77),
      alignment: Alignment.center,
      decoration: BoxDecoration(
          image: DecorationImage(
              fit: BoxFit.fitWidth,
              image: AssetImage(
                SPClassImageUtil.spFunGetImagePath("ic_aidetail_main"),
              )
          )
      ),
      child: Text('数据不足努力分析中...',style: TextStyle(color: Colors.white,fontSize: sp(14)),),
    );
  }

  getData(){
    SPClassApiManager.spFunGetInstance().spFunMatchAiDetail<MatchAiDetailEntity>(params:{'guess_match_id':widget.matchId},spProCallBack:SPClassHttpCallBack(
        spProOnSuccess: (result){
          data = result;
              setState(() {
          });
        }
    ));
  }

  void spFunShowConfirmDialog(int type) {
    //type  1 单场  2 周 3月
    SPClassDialogUtils.spFunShowConfirmDialog(context,RichText(
      text: TextSpan(
        text: "支付",
        style: TextStyle(fontSize: 16, color: Color(0xFF333333)),
        children: <TextSpan>[
          TextSpan(text:type==1?data?.spProAiVip?.spProAiSinglePrice:type==2?data?.spProAiVip?.spProAiWeekPrice:data?.spProAiVip?.spProAiPrice, style: TextStyle(fontSize: 16, color: Color(0xFFE3494B))),
          TextSpan(text: "钻石"),
          TextSpan(text: type==1?'购买AI赛事预测':"订阅AI赛事预测"),
        ],
      ),
    ), (){
      if(type==1){
        SPClassApiManager.spFunGetInstance().spFunMatchBuySingleAi<SPClassBaseModelEntity>(params: {'guess_match_id':widget.matchId},context: context,spProCallBack: SPClassHttpCallBack(
            spProOnSuccess: (value){
              getData();
            },
            onError: (value){
              if( value.code=="200"){
                SPClassNavigatorUtils.spFunPushRoute(context,  SPClassRechargeDiamondPage());
              }
            }
        ));
      }else{
        SPClassApiManager.spFunGetInstance().spFunMatchBuyAi<SPClassBaseModelEntity>(params: {'match_type':widget.matchType,'buy_type':type==2?'week':'month'},context: context,spProCallBack: SPClassHttpCallBack(
            spProOnSuccess: (value){
              getData();
            },
            onError: (value){
              if( value.code=="200"){
                SPClassNavigatorUtils.spFunPushRoute(context,  SPClassRechargeDiamondPage());
              }
            }
        ));
      }

    });
  }

}
